<template>
  <div class="business-list-item" @click="handleShopBtn">
    <img :src="`http://elm.cangdu.org/img/${item.image_path}`" alt="" />
    <div class="text">
      <div class="title">
        <span class="brand">品牌</span>
        <span class="name">{{ item.name }}</span>
        <ul class="supports">
          <li v-for="record in item.supports">
            {{ record.icon_name }}
          </li>
        </ul>
      </div>
      <div class="score">
        <div class="left">
          <div class="starts">
            <i v-for="number in 4" class="front"></i>
            <i
              class="last"
              :style="{ 'background-position': startPosition }"
            ></i>
          </div>
          <div>
            <span class="rating">
              {{ item.rating }}
            </span>
            <span class="monthly-sales">
              月销{{ item.recent_order_num }}单
            </span>
          </div>
        </div>
        <div class="right">
          <span class="delivery-mode" v-if="item.delivery_mode">
            {{ item.delivery_mode.text }}
          </span>
          <span class="punctual" v-if="item.supports[1]">
            {{ item.supports[1].name }}
          </span>
        </div>
      </div>
      <div class="distance">
        <span class="distribution"
          >¥{{ item.float_minimum_order_amount }}起送 /
          {{ item.piecewise_agent_fee.tips }}</span
        >
        <span class="mileage"
          >{{ item.distance }} /
          <span class="time"> {{ item.order_lead_time }} </span></span
        >
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  props: {
    item: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    ...mapGetters(['geohash']),
    startPosition() {
      if (this.item.rating <= 4) {
        return "0 40px";
      } else if (this.item.rating < 4.5) {
        return "0 20px";
      } else {
        return "0 30px";
      }
    },
  },
  methods: {
    handleShopBtn() {
      this.$bus.$emit("handleShopBtn", this.item.latitude, this.item.longitude);
      this.$router.push({
        path: "/shop",
        query: {
          geohash: this.geohash,
          id: this.item.id,
        },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.business-list-item {
  display: flex;
  padding: 15px 10px;
  border-bottom: 1px solid #ccc;
  img {
    width: 60px;
    height: 60px;
    margin-right: 10px;
  }
  .text {
    flex: 1;
    .title {
      display: flex;
      align-items: center;
      .brand {
        padding: 1px 2px;
        border-radius: 3px;
        margin-right: 10px;
        background-color: #e2d930;
        font-weight: bold;
        color: #222222;
      }
      .name {
        flex: 1;
        font-size: 15px;
        font-weight: bold;
        color: #333435;
        // white-space: nowrap;
        // overflow: hidden;
        // text-overflow: ellipsis;
      }
      .supports {
        display: flex;
        font-size: 10px;
        li {
          padding: 2px;
          border: 1px solid #f6f6f6;
          background-color: #f6f6f6;
          color: #999999;
          font-size: 12px;
        }
        & li:nth-child(2) {
          border-right: none;
          border-left: none;
        }
      }
    }
  }
  .score {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
    font-size: 8px;
    .left {
      display: flex;
      .starts {
        .front,
        .last {
          display: inline-block;
          width: 10px;
          height: 10px;
          background-image: url("~assets/img/msite/start.png");
          background-size: 100%;
        }
      }
      .rating {
        font-size: 10px;
        margin: 0 8px;
      }
    }
    .right {
      .delivery-mode {
        padding: 2px;
        background-color: #3190e8;
        color: #fff;
      }
      .punctual {
        margin-left: 2px;
        padding: 1px;
        border: 1px solid #7ab7ef;
      }
    }
  }
  .distance {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 11px;
    .mileage {
      .time {
        color: #af9eec;
      }
    }
  }
}
</style>